package demo.test.bean;

import com.just_bean.core.bean.BaseBean;
import com.just_bean.core.exception.BeanInitException;
import demo.test.anno.Time;

public class TimeBean extends BaseBean<Time> {
    private long second = 0;
    private long curTime = 0;
    private Object instance;

    public TimeBean(Class clz, Time time) throws Exception {
        super(clz, time);
        this.second = time.second();
    }

    @Override
    public boolean check(Object... cond) {
        return false;
    }

    @Override
    public Object get() throws BeanInitException {
        if (System.currentTimeMillis() - curTime > second) {
            this.curTime = System.currentTimeMillis();
            return instance = this.create();
        } else {
            return instance;
        }
    }
}
